package com.example.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.bean.CmsEnter;
import com.example.demo.common.Response;
import com.example.demo.service.CmsEnterService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


@Api(tags = " 用户登录服务")
@RestController
@RequestMapping("/enter")
public class CmsEnterController {
	
	@Autowired
	CmsEnterService enterService;
	
	@ApiOperation(value = " 管理/员工登录")
	@PostMapping("/enter")
	public Response<String> enterID(String eid,String password){
		CmsEnter p = enterService.selectById(eid);
		if(password.contentEquals(p.getPassword())){
			if("A".contentEquals(p.getStatus())){
				global.key = 1;
			}
			else {
				global.key = 0;
			}
		System.out.println(global.key);
		return Response.ok("success");
		}
		System.out.println(global.key);
		return Response.error("fail");
		}
	
	@ApiOperation(value = "列出所有管理/员工数据")
	@GetMapping("/All")
	public Response<List<CmsEnter>> findAll(){
		if(global.key==1) {
		List<CmsEnter> all = enterService.findAll();
		return Response.ok(all);}
		return null;
	}
	
	@ApiOperation(value = "按id来找出管理/员工数据")
	@GetMapping("/select")
	public Response<CmsEnter> selectById(String id){
		if(global.key==1) {
		CmsEnter data = enterService.selectById(id);
		return Response.ok(data);}
		return null;
	}
	
	@ApiOperation(value = "按id来删除管理/员工数据")	
	@DeleteMapping("/deleteById")
	public Response<String> deleteById(String id){
		int count = enterService.deleteById(id);
		return Response.ok("删除成功了"+count);
	}

	@ApiOperation(value = "更改管理/员工数据")
	@PostMapping("/saveOrUpdateCmsEnter")
	public Response<String> saveOrUpdate(CmsEnter enter){
		enterService.saveOrUpdate(enter);
		return Response.ok("操作成功!");
	}
	
}























